package net.tv90.bfmccore.command;

import net.tv90.bfmccore.squad.Squad;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SquadCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("squad")) {
            if (args.length == 0) {
                sender.sendMessage("/squad kickall 让游戏中所有玩家退出他们所在的小队");
                sender.sendMessage("/squad kick <玩家> 强制玩家退出小队");
                sender.sendMessage("/squad join <队伍编号> <玩家> 加入别的队伍");
                sender.sendMessage("/squad joinrandom <玩家> 随机进入某个小队");
                sender.sendMessage("/squad tp <玩家> 传送到小队长所在的位置");
                sender.sendMessage("/squad invite <玩家> 邀请某玩家加入小队");
                //sender.sendMessage("/squad tpleader [小队名称] 传送到其他小队长的位置（只有小队长可以用此指令）");
            }
            if (args[0].equalsIgnoreCase("kickall")) {
                Squad.clearSquadMap();
            }
            if (args[0].equalsIgnoreCase("kick")) {
                Player player = Bukkit.getPlayerExact(args[1]);
                Squad.quit(player);
            }
            if (args[0].equalsIgnoreCase("join")) {
                int index = Integer.parseInt(args[1]);
                Player player = Bukkit.getPlayerExact(args[2]);
                Squad.join(player, index);
            }
            if (args[0].equalsIgnoreCase("joinrandom")) {
                Player player = Bukkit.getPlayerExact(args[1]);
                Squad.joinRandom(player);
            }
            if (args[0].equalsIgnoreCase("tp")) {
                Player player = Bukkit.getPlayerExact(args[1]);
                Squad.teleportToLeader(player);
            }
            if (args[0].equalsIgnoreCase("invite")) {
                if(sender instanceof Player){
                    Player invitee = Bukkit.getPlayerExact(args[1]);
                    if (invitee != null) {
                        Squad.invite((Player) sender,invitee);
                    } else {
                        sender.sendMessage("§a[队伍]该玩家不存在!");
                    }
                }
            }
        }
        if (label.equalsIgnoreCase("sq")) {
            if (args.length == 0) {
                sender.sendMessage("/sq invite <玩家> 邀请某玩家加入你的小队");
            }
            if (args[0].equalsIgnoreCase("invite")) {
                if(sender instanceof Player){
                    Player invitee = Bukkit.getPlayerExact(args[1]);
                    if (invitee != null) {
                        Squad.invite((Player) sender,invitee);
                    } else {
                        sender.sendMessage("§a[队伍]该玩家不存在!");
                    }
                    return true;
                }
            }
        }
        return false;
    }
}
